package com.learn.post_processor;

import com.learn.post_processor.beans.service.UserServiceImpl;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class PostProcessor {
    public static void main(String[] args) {
        // 后处理器：介入Spring实例化Bean的流程中
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("post-processor.xml");
        
        // BeanFactoryPostProcessor：（一次）beanDefinitionMap填充后，beanDefinitionMap遍历创建Bean实例对象前
        //      实现：实现BeanFactoryPostProcessor接口的类交给Spring容器管理
        System.out.println(applicationContext.getBean("userDao"));
        System.out.println(applicationContext.getBean("userDao(new)"));
        System.out.println(applicationContext.getBean("userDao(new-interface)"));
        
        /*
        BeanDefinitionRegistryPostProcessor：继承BeanFactoryPostProcessor的接口，用于动态注册BeanDefinition
        BeanFactoryPostProcessor：（一次）beanDefinitionMap填充后，beanDefinitionMap遍历创建Bean实例对象前
        */
        
        // BeanPostProcessor：（每次创建Bean）遍历beanDefinitionMap每次创建Bean实例对象后，填充进入singletonObjects前
        //      实现：实现BeanPostProcessor接口的类交给Spring容器管理
        System.out.println(applicationContext.getBean("userService", UserServiceImpl.class).getName());
        
        /*
        实例化UserDaoImpl
        (before)BeanPostProcessorImpl：（每次创建Bean）遍历beanDefinitionMap每次创建Bean实例对象后，填充进入singletonObjects前
        (before)beanName:userDao
        (after)BeanPostProcessorImpl：（每次创建Bean）遍历beanDefinitionMap每次创建Bean实例对象后，填充进入singletonObjects前
        (after)beanName:userDao
        实例化UserServiceImpl
        (before)BeanPostProcessorImpl：（每次创建Bean）遍历beanDefinitionMap每次创建Bean实例对象后，填充进入singletonObjects前
        (before)beanName:userService
        (after)BeanPostProcessorImpl：（每次创建Bean）遍历beanDefinitionMap每次创建Bean实例对象后，填充进入singletonObjects前
        (after)beanName:userService
        hhhh
        */
    }
}
